import { Command } from '../constant';
import Taro from '@tarojs/taro';
import { Dispatch } from 'typings';
import { IAllReducerProps } from '../types';
import { getReducerData } from '@/redux/store';
import { extraPathsValue } from '@/redux/util';
import api from 'api';
export default (dispatch: Dispatch) => {
  let action = {
    commonChange(...param: any) {
      dispatch({
        type: Command.commonChange,
        payload: extraPathsValue(...arguments),
      });
    },

    async page() { },

    async received() {
      const result = await api.receivedMemberController.receivedMember();
      if (result?.code == 'K-000000') {
        Taro.showToast({
          title: '领取成功',
          icon: 'none',
          duration: 1000,
        });
        // Taro.setStorageSync('doubleMemModel', false);
        Taro.setStorageSync('memberReceived', true);
        setTimeout(() => {
          Taro.switchTab({ url: '/pages/index/index' });
        }, 1000);
      } else {
        Taro.showToast({
          title: result?.message,
          icon: 'none',
          duration: 1000,
        });
      }
    }
  };
  return action;
};

function getData(): IAllReducerProps {
  return {
    main: getReducerData('packageAComplimentaryMain'),
  };
}

//create by moon https://github.com/creasy2010/moon
